﻿using AuthCenter_HuangJingtao.Domain;
using AuthCenter_HuangJingtao.ErrorCode;
using AuthCenter_HuangJingtao.Infrastructure.Imterfaces;
using AuthCenter_HuangJingtao.Read.Api.Application.Command.AppaLL;
using MediatR;
using Microsoft.EntityFrameworkCore;

namespace AuthCenter_HuangJingtao.Read.Api.Application.CommandHandler.AppHandler
{
    public class DelCommandHandler : IRequestHandler<DelCommand, ApiResult<int>>
    {
        IBaseReponsitory<App> Apps;

        public DelCommandHandler(IBaseReponsitory<App> Apps)
        {
            this.Apps = Apps;
        }

        public async Task<ApiResult<int>> Handle(DelCommand request, CancellationToken cancellationToken)
        {
            var list =await Apps.GetQuery().FirstOrDefaultAsync(c=>c.App_Id==request.id);
            list.App_IsDel = true;
            await Apps.UpdateAsync(list);
            return new ApiResult<int>
            {
                Code = ApiEnum.Success,
                Message = "删除成功",
                Data = 1

            };
        }
    }
}
